<template>
    <div id="app">
        <div class="view">
            <theme></theme>
            <router-view></router-view>
            <commonTheme></commonTheme>
        </div>
    </div>
</template>

<script>
import theme from './common/js/themeWrap.vue'
import commonTheme from './common/components/yjTheme'
import { mapState } from 'vuex'

export default {
    name: 'app',
    data () {
        return {
        }
    },
    components: {
        theme,
        commonTheme
    },
    methods: {
    },
    computed: {
         ...mapState(
            [
                'tipShow',
                'tip'
            ]
        )
    },
    beforeCreate () {
        this.$store.commit('setIp', config.ip)
        this.$store.commit('setOssUrl', config.ossUrl)
        document.body.className = ''
        let atag = document.createElement('a')
        atag.href = decodeURIComponent(window.location.href)
        let queryStr = atag.href.split('?')[1]
        if (queryStr) {
            let queryStr2 = queryStr.split('&')
            console.log(queryStr2)
            let obj = {}
            for (var i = 0; i < queryStr2.length; i++) {
                obj[queryStr2[i].split('=')[0]] = decodeURIComponent(queryStr2[i].split('=')[1])
            }
            console.log((obj))
            this.$store.commit('setTheme', obj.theme || '#409eff')
            // source :0、休闲商家列表   1、酒吧  2、养生 3、修改代理商管理 4、代理商方案设置 5、管理员身份应用商城入口
            if (obj['source'] === '2') {
                document.body.className = 'yjTheme'
            }
            this.$store.commit('setLoginParams', obj)
            if (obj['IsImplant'] === '1') {
                this.$store.commit('setIsImplant', true)
            } else {
                this.$store.commit('setIsImplant', false)
            }
            if (obj['source'] === '0' || obj['source'] === '3') {
                this.$store.commit('setServiceMenu', 0)
            } else if (obj['source'] === '4') {
                this.$store.commit('setServiceMenu', 2)
            } else if (obj['source'] === '5') {
                this.$store.commit('setServiceMenu', 3)
            } else {
                this.$store.commit('setServiceMenu', 1)
            }
            // 接口 权限
            this.$store.commit('setTokens', obj['tokens'] || '')
            this.$store.commit('setTimestamp', obj['timestamp'] || '')
            this.$store.commit('setSignature', obj['signature'] || '')
            // 操作者信息
            let buyStaffInfo = {
                adminId: obj['adminId'] || '',
                buyStaffType: obj['buyStaffType'] || '',
                buyStaffId: obj['buyStaffId'] || '',
                buyStaffName: obj['buyStaffName'] || ''
            }
            this.$store.commit('setBuyStaffInfo', buyStaffInfo)
            // 账户信息
            let userInfo = {
                companyCode: obj['companyCode'] || '',
                companyName: obj['companyName'] || '',
                managementType: obj['managementType'] || '',
                companyId: obj['companyId'] || ''
            }
            this.$store.commit('setUserInfo', userInfo)
        }
    },
    created () {
        console.dir(this.$store.state.ip)
    },
    watch: {
        tipShow () {
            this.$message({
                message: this.$store.state.msg,
                type: 'warning'
            })
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
@import './common/stylus/mixin.styl'
@import '../static/css/animate.css'
@import '../static/css/variables'

body
    /* background url("./common/pic/bg.png") */
    background-repeat: no-repeat
    background-size: cover
    background-attachment: fixed

#app
    position: absolute
    width: 100%
    height: 100%
    top: 0
    left: 0
    font-family: 'Microsoft yahei'

    .view
        position: absolute
        top: 0
        bottom: 0
        width: 100%
</style>